#!/bin/bash

cmd=${1}

if [[ ${cmd} == "configure" && ! -d "build/" ]]; then
	mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release && exit 0
elif [[ ${cmd} == "configure" ]]; then
	cd build && rm -rf * && cmake .. -DCMAKE_BUILD_TYPE=Release  && exit 0
elif [[ ${cmd} == "build" ]]; then
	cd build && make  && exit 0
fi

config="null"
data="null"

if [[ ${cmd} == "node_2d_demo_1" ]]; then
	config="data/2D_demo_1/demo"
	data="data/2D_demo_1/out/demo.1.msh"
	./build/bin/mt2d_node ${config}

elif [[ ${cmd} == "edge_2d_demo_1" ]]; then
	config="data/2D_demo_1/demo"
	data="data/2D_demo_1/out/demo.1.msh"
	./build/bin/mt2d_edge ${config}

elif [[ ${cmd} == "edge_ho_2d_demo_1" ]]; then
	config="data/2D_demo_1/demo"
	data="data/2D_demo_1/out/demo.1.msh"
	./build/bin/mt2d_edge_ho ${config}

elif [[ ${cmd} == "edge_total_2d_demo_1" ]]; then
	config="data/2D_demo_1/demo_total"
	data="data/2D_demo_1/out/demo.1.msh"
	./build/bin/mt2d_edge_total ${config}

elif [[ ${cmd} == "aniso_2d_demo_1" ]]; then
	config="data/2D_demo_1/demo_aniso"
	data="data/2D_demo_1/out/demo.1.msh"
	./build/bin/mt2d_aniso ${config}

elif [[ ${cmd} == "node_2d_demo_2" ]]; then
	config="data/2D_demo_2/demo2"
	data="data/2D_demo_2/out/demo2.1.msh"
	./build/bin/mt2d_node ${config}

elif [[ ${cmd} == "edge_total_2d_demo_2" ]]; then
	config="data/2D_demo_2/demo2_total"
	data="data/2D_demo_2/out/demo2.1.msh"
	./build/bin/mt2d_edge_total ${config}

elif [[ ${cmd} == "node_2d_demo_3" ]]; then
	config="data/2D_demo_2/demo3"
	data="data/2D_demo_2/out/demo2.1.msh"
	./build/bin/mt2d_node ${config}

elif [[ ${cmd} == "edge_2d_demo_3" ]]; then
	config="data/2D_demo_3/demo3"
	data="data/2D_demo_3/out/demo3.1.msh"
	./build/bin/mt2d_edge ${config}

elif [[ ${cmd} == "node_2d_demo_4" ]]; then
	config="data/2D_demo_4/demo4"
	data="data/2D_demo_4/out/demo4.1.msh"
	./build/bin/mt2d_node ${config}

elif [[ ${cmd} == "edge_2d_demo_4" ]]; then
	config="data/2D_demo_4/demo4"
	data="data/2D_demo_4/out/demo4.1.msh"
	./build/bin/mt2d_edge ${config}

elif [[ ${cmd} == "edge_total_2d_demo_3" ]]; then
	config="data/2D_demo_3/demo3"
	data="data/2D_demo_3/out/demo3.1.msh"
	./build/bin/mt2d_edge_total ${config}

elif [[ ${cmd} == "3d_demo_1" ]]; then
	config="data/3D_demo_1/demo"
	data="data/3D_demo_1/out/demo.1.msh"
	./build/bin/mt3d ${config}

elif [[ ${cmd} == "3d_demo_1_cuda" ]]; then
	config="data/3D_demo_1/demo"
	data="data/3D_demo_1/out/demo.1.msh"
	./build/bin/mt3d_cuda ${config}

elif [[ ${cmd} == "3d_demo_2" ]]; then
	config="data/3D_demo_2/demo2"
	data="data/3D_demo_2/out/demo2.1.msh"
	./build/bin/mt3d ${config}

elif [[ ${cmd} == "3d_demo_2_cuda" ]]; then
	config="data/3D_demo_2/demo2"
	data="data/3D_demo_2/out/demo2.1.msh"
	./build/bin/mt3d_cuda ${config}

elif [[ ${cmd} == "3d_demo_3" ]]; then
	config="data/3D_demo_3/demo3"
	data="data/3D_demo_3/out/demo3.1.msh"
	./build/bin/mt3d ${config}

elif [[ ${cmd} == "3d_demo_4" ]]; then
	config="data/3D_demo_4/demo4"
	data="data/3D_demo_4/out/demo4.1.msh"
	./build/bin/mt3d ${config}

elif [[ ${cmd} == "3d_demo_4_cuda" ]]; then
	config="data/3D_demo_4/demo4"
	data="data/3D_demo_4/out/demo4.1.msh"
	./build/bin/mt3d_cuda ${config}

elif [[ ${cmd} == "3d_demo_5" ]]; then
	config="data/3D_demo_5/demo5"
	data="data/3D_demo_5/out/demo5.1.msh"
	./build/bin/mt3d ${config}

elif [[ ${cmd} == "3d_demo_5_cuda" ]]; then
	config="data/3D_demo_5/demo5"
	data="data/3D_demo_5/out/demo5.1.msh"
	./build/bin/mt3d_cuda ${config}

elif [[ ${cmd} == "3d_demo_5_cuda_dia" ]]; then
	config="data/3D_demo_5/demo5"
	data="data/3D_demo_5/out/demo5.1.msh"
	./build/bin/mt3d_cuda_dia ${config}

else
	echo "Invalid demo name"
	exit -1
fi

system=`uname`

#if [[ "Linux" == ${system} ]]; then
#	gmsh ${data}
#elif [[ "Darwin" == ${system} ]]; then
#	open -a Gmsh ${data}
#fi